﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Ec_System.Facade.Web;
using Ec_System.Models.Web;
using Webdiyer.WebControls.Mvc;

namespace Ec_System.WebUI.Areas.Web.Controllers
{
    public class ManufacturerController : Controller
    {
        ManufacturerFacade manufacturerFacade = new ManufacturerFacade();

       /// <summary>
       /// 品牌列表
       /// </summary>
       /// <param name="id"></param>
       /// <returns></returns>
        public ActionResult Index(int id = 1)
        {
            ManufacturerDataRequest request = new ManufacturerDataRequest()
            {
                PageIndex = id,
                PageSize = 32
            };
            var result = manufacturerFacade.GetManufacturerListWithPage(request);

            var model = new PagedList<ManufacturerData>(result.Result, request.PageIndex, request.PageSize, result.TotalCount);
            return View(model);
        }

        /// <summary>
        /// 品牌产品
        /// </summary>
        /// <param name="mID"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public ActionResult ProductList(int mID, int pageIndex = 1)
        {
            ShopProductDataRequest request = new ShopProductDataRequest()
            {
                PageIndex = pageIndex,
                PageSize = 32,
                ManufacturerID = mID
            };

            var result = manufacturerFacade.GetProductListByMidWithPage(request);
            var model = new PagedList<ShopProductData>(result.Result, request.PageIndex, request.PageSize, result.TotalCount);
            ViewData["view"] = "productList";

            return View("Index", model);
        }
    }
}